import os

# 设置要操作的根目录
base_dir = "/home/a/work/vlog/local/clean"

# 获取当前目录下的所有子目录
def get_subdirectories():
    """获取指定目录下的所有子目录"""
    return [d for d in os.listdir(base_dir) if os.path.isdir(os.path.join(base_dir, d))]

def count_files(subdir, base_dir):
    """统计子目录中 .mp4 文件的个数"""
    dir_path = os.path.join(base_dir, subdir)
    if not os.path.exists(dir_path):
        print(f"Directory {dir_path} does not exist, skipping...")
        return 0

    # 获取所有 .mp4 文件
    mp4_files = [f for f in os.listdir(dir_path) if f.endswith(".mp4")]
    tmp_files = [f for f in os.listdir(dir_path) if f.endswith(".tmp")]

    # 返回文件个数
    return [len(mp4_files), len(tmp_files)]

# 获取当前目录下的所有子目录
subdirs = get_subdirectories()

# 遍历每个子目录并统计 .mp4 文件个数
for subdir in subdirs:
    mp4_file_count, tmp_file_count = count_files(subdir, base_dir)
    print(f"{subdir} contains {mp4_file_count} .mp4 files, contains {tmp_file_count} .tmp files")
